package com.youzikj.wx.core.utils;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;

public class PosterUtil {
	
	 public static  String overlapImage(HttpServletRequest request,String openid,String bigPath, String smallPath) {
		 String filePath = null;
		 try {
		      BufferedImage big = ImageIO.read(new File(bigPath));
		      BufferedImage small = ImageIO.read(new File(smallPath));
		      Graphics2D g = big.createGraphics();
		      int x = (big.getWidth() - small.getWidth()) / 2;
		      int y = (big.getHeight() - small.getHeight()) / 2 +150;
		      g.drawImage(small, x, y, small.getWidth(), small.getHeight(), null);
		      g.dispose();
		      String path = request.getSession().getServletContext().getRealPath(File.separator);
			  path += File.separator + "upload" + File.separator;
			   filePath = path +"poster"+openid +".jpg";
		      ImageIO.write(big, "jpg", new File(filePath));
		    } catch (Exception e) {
		      e.printStackTrace();
		    }
		    return filePath;
	 }	    



}
